package com.ruoyi.framework.security.captcha;

import com.google.code.kaptcha.GimpyEngine;

import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * 自定义的视觉干扰器
 */
public class MyObscurificatorImpl implements GimpyEngine {

    public BufferedImage getDistortedImage(BufferedImage baseImage) {
        Graphics2D graph = (Graphics2D)baseImage.getGraphics();
        int imageHeight = baseImage.getHeight();
        int imageWidth = baseImage.getWidth();

        int[] pix = new int[imageHeight * imageWidth];
        int j = 0;

        for(int j1 = 0; j1 < imageWidth; ++j1) {
            for(int k1 = 0; k1 < imageHeight; ++k1) {
                pix[j] = baseImage.getRGB(j1, k1);
                ++j;
            }
        }
        return baseImage;
    }

    private int ranInt(int i, int j) {
        double d = Math.random();
        return (int)((double)i + (double)(j - i + 1) * d);
    }

    private double fishEyeFormula(double s) {
        if (s < 0.0) {
            return 0.0;
        } else {
            return s > 1.0 ? s : -0.75 * s * s * s + 1.5 * s * s + 0.25 * s;
        }
    }

}
